import Vue from 'vue'
// import vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({

    state: {
        num: 100
    },
    // 按钮的
    mutations: {
        addNum(state, val) {
            state.num += val
        },
        subNum(state, val) {
            state.num -= val
        },
        setNum(state, val) {
            state.num = val
        }
    },
    actions: {
        asyncAddNum(store, val = 1) {
            setTimeout(() => {
                store.commit('addNum', val)
            }, 1500)
        },
        asyncSubNum(store,val = 1){
            setTimeout(()=>{
                store.commit('subNum',val)
            },1500)
        }
    },
})

export default store